﻿using System.Text;

namespace Medianamik.Core.DAL.SQL.Clauses
{
    // On en supporte 1 pour l'instant.
    public class XmlCrossApplyClause : CrossApplyClause
    {
        public Column XmlColumn { get; set; }
        public string Xpath { get; set; }
        public string Alias { get { return "T(c)"; } }

        public XmlCrossApplyClause(Column xmlColumn, string xpath)
        {
            XmlColumn = xmlColumn;
            Xpath = xpath;
        }

        public override StringBuilder ToSQL()
        {
            return new StringBuilder(string.Format(" CROSS APPLY {0}.nodes('{1}') as {2} ", XmlColumn.Name, Xpath, Alias));
        }
    }
}
